package com.socialuni.center.web.controller;

import com.socialuni.sdk.api.model.ResultRO;
import com.socialuni.center.web.model.DO.config.HomeSwiperDO;
import com.socialuni.center.web.repository.config.HomeSwiperRepository;
import com.socialuni.center.web.utils.DevAccountUtils;
import com.socialuni.sdk.constant.StatusConst;
import com.socialuni.sdk.model.RO.HomeSwiperVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

//清池专用的
@RestController
@RequestMapping("socialuni/qingchi")
public class QingchiController {
    @Resource
    private HomeSwiperRepository homeSwiperRepository;

    @GetMapping("queryHomeSwipers")
    public ResultRO<List<HomeSwiperVO>> queryHomeSwipers() {
        //homeSwipers
        List<HomeSwiperDO> homeSwiperDOS = homeSwiperRepository.findAllByStatusAndDevIdOrderByTopLevelAscIdDesc(StatusConst.enable,  DevAccountUtils.getDevId());
        return new ResultRO<>(homeSwiperDOS.stream().map(HomeSwiperDO::toVO).collect(Collectors.toList()));
    }
}
